package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.common.RiskwarningConstant;
import com.fdb.efp.nls.service.dao.PspSpecCheckCusDao;
import com.fdb.efp.nls.service.domain.PspSpecCheckCus;
import com.fdb.efp.nls.service.facade.PspSpecCheckCusService;
import com.fdb.efp.nls.service.vo.PspSpecCheckCusVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 专项检查客户表				<p>
 * @author ligm
 * @date 2019-09-04
 */
@Service("pspSpecCheckCusService")
public class PspSpecCheckCusServiceImpl implements PspSpecCheckCusService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PspSpecCheckCusServiceImpl.class);

	@Autowired
	private PspSpecCheckCusDao pspSpecCheckCusDao;
	
	/**
	 * 新增操作
	 */
	public int insertPspSpecCheckCus(PspSpecCheckCusVO inPspSpecCheckCusVo) {
		logger.debug("当前新增数据为:"+ inPspSpecCheckCusVo.toString());
		int num = 0;
		try {
			PspSpecCheckCus pspSpecCheckCus = new PspSpecCheckCus();
			beanCopy(inPspSpecCheckCusVo, pspSpecCheckCus);
			num = pspSpecCheckCusDao.insertPspSpecCheckCus(pspSpecCheckCus);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 批量新增操作
	 *create by luzy 2019/10/17
	 * */
	public int insertPspSpecCheckCusList(List<PspSpecCheckCusVO> pspSpecCheckCusVOList) {
		logger.debug("当前新增数据为:"+ pspSpecCheckCusVOList.toString());
		int num = 0;
		try {
			num = pspSpecCheckCusDao.insertPspSpecCheckCusList(pspSpecCheckCusVOList);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PspSpecCheckCusVO inPspSpecCheckCusVo) {
		logger.debug("当前删除数据条件为:"+ inPspSpecCheckCusVo);
		int num = 0;
		try {
			PspSpecCheckCus pspSpecCheckCus = new PspSpecCheckCus();
			beanCopy(inPspSpecCheckCusVo, pspSpecCheckCus);
			num = pspSpecCheckCusDao.deleteByPk(pspSpecCheckCus);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPspSpecCheckCusVo +"删除的数据条数为"+ num);
		return num;
	}

	/**
	 * create by luzy
	 * description 根据任务编号及用户编号删除数据
	 * 删除操作
	 */
	public int deleteOneInfo(PspSpecCheckCusVO inPspSpecCheckCusVo) {
		logger.debug("当前删除数据条件为:"+ inPspSpecCheckCusVo);
		int num = 0;
		try {
			PspSpecCheckCus pspSpecCheckCus = new PspSpecCheckCus();
			beanCopy(inPspSpecCheckCusVo, pspSpecCheckCus);
			num = pspSpecCheckCusDao.deleteOneInfo(pspSpecCheckCus);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPspSpecCheckCusVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 *
	 */
	public int updateByPk(PspSpecCheckCusVO inPspSpecCheckCusVo) {
		logger.debug("当前修改数据为:"+ inPspSpecCheckCusVo.toString());
		int num = 0;
		try {
			PspSpecCheckCus pspSpecCheckCus = new PspSpecCheckCus();
			beanCopy(inPspSpecCheckCusVo, pspSpecCheckCus);
			num = pspSpecCheckCusDao.updateByPk(pspSpecCheckCus);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPspSpecCheckCusVo +"修改的数据条数为"+ num);
		return num;
	}
	/**
	 * 批量导入选取，根据主键修改主键
	 * create: luzhaoyu 2019/9/29
	 *
	 */
	public int updateBizSerno(PspSpecCheckCusVO inPspSpecCheckCusVo) {
		logger.debug("当前修改数据为:"+ inPspSpecCheckCusVo.toString());
		int num = 0;
		try {
			PspSpecCheckCus pspSpecCheckCus = new PspSpecCheckCus();
			beanCopy(inPspSpecCheckCusVo, pspSpecCheckCus);
			num = pspSpecCheckCusDao.updateBizSerno(pspSpecCheckCus);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPspSpecCheckCusVo +"修改的数据条数为"+ num);
		return num;
	}
	/**
	 * 根据用户编号和任务编号更新操作
	 * luzhaoyu	2019/9/27
	 */
	public int updateCusIdByPk(PspSpecCheckCusVO inPspSpecCheckCusVo) {
		logger.debug("当前修改数据为:"+ inPspSpecCheckCusVo.toString());
		PspSpecCheckCus pspSpecCheckCus = new PspSpecCheckCus();
		int num = 0;
		try {
			beanCopy(inPspSpecCheckCusVo, pspSpecCheckCus);
			num = pspSpecCheckCusDao.updateCusIdByPk(pspSpecCheckCus);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPspSpecCheckCusVo +"修改的数据条数为"+ num);
		return num;
	}

	/**
	 * 查询操作
	 */
	public PspSpecCheckCusVO queryByPk(PspSpecCheckCusVO inPspSpecCheckCusVo) {

		logger.debug("当前查询参数信息为:"+ inPspSpecCheckCusVo);
		try {
			PspSpecCheckCus queryPspSpecCheckCus = new PspSpecCheckCus();
			beanCopy(inPspSpecCheckCusVo, queryPspSpecCheckCus);
			PspSpecCheckCus queryRslPspSpecCheckCus = pspSpecCheckCusDao.queryByPk(queryPspSpecCheckCus);
			if (Objects.nonNull(queryRslPspSpecCheckCus)) {
				PspSpecCheckCusVO outPspSpecCheckCusVo = beanCopy(queryRslPspSpecCheckCus, new PspSpecCheckCusVO());
				logger.debug("当前查询结果为:"+ outPspSpecCheckCusVo.toString());
				return outPspSpecCheckCusVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 根据cusId 查询操作
	 * create by luzy 2019/10/12
	 *
	 */
	public PspSpecCheckCusVO queryCusByPk(PspSpecCheckCusVO inPspSpecCheckCusVo) {
		logger.debug("当前查询参数信息为:"+ inPspSpecCheckCusVo);
		try {
			PspSpecCheckCus queryPspSpecCheckCus = new PspSpecCheckCus();
			queryPspSpecCheckCus.setCusId(inPspSpecCheckCusVo.getCusId());
			queryPspSpecCheckCus.setChkName(RiskwarningConstant.PSP_CHK_NAME);
			queryPspSpecCheckCus.setChkInputSts(RiskwarningConstant.STD_ZX_CHK_STATE_00);
			PspSpecCheckCus queryRslPspSpecCheckCus = pspSpecCheckCusDao.queryCusByPk(queryPspSpecCheckCus);
			if (Objects.nonNull(queryRslPspSpecCheckCus)) {
				PspSpecCheckCusVO outPspSpecCheckCusVo = beanCopy(queryRslPspSpecCheckCus, new PspSpecCheckCusVO());
				logger.debug("当前查询结果为:"+ outPspSpecCheckCusVo.toString());
				return outPspSpecCheckCusVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * create: luzhaoyu  2019/10/16
	 * 查询登记未完成的代码
	 */
	public List<PspSpecCheckCusVO> querychkInputSts(PspSpecCheckCusVO pspSpecCheckCusVo) {
		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PspSpecCheckCusVO> list = null;
		try {
			List<PspSpecCheckCus> pspSpecCheckCuss = pspSpecCheckCusDao.querychkInputSts(pspSpecCheckCusVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pspSpecCheckCuss.size());
			pageSet(pspSpecCheckCuss, pspSpecCheckCusVo);
			list = (List<PspSpecCheckCusVO>) beansCopy(pspSpecCheckCuss, PspSpecCheckCusVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	/**
	 * create: luzhaoyu  2019/9/27
	 * 查询操作
	 */
	public List<PspSpecCheckCusVO> queryListCusInfo(PspSpecCheckCusVO pspSpecCheckCusVo) {
		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PspSpecCheckCusVO> list = null;
		try {
			List<PspSpecCheckCus> pspSpecCheckCuss = pspSpecCheckCusDao.queryListCusInfoByPage(pspSpecCheckCusVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pspSpecCheckCuss.size());
			pageSet(pspSpecCheckCuss, pspSpecCheckCusVo);
			list = (List<PspSpecCheckCusVO>) beansCopy(pspSpecCheckCuss, PspSpecCheckCusVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PspSpecCheckCusVO> queryAllOwner(PspSpecCheckCusVO pspSpecCheckCusVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PspSpecCheckCusVO> list = null;
		try {
			List<PspSpecCheckCus> pspSpecCheckCuss = pspSpecCheckCusDao.queryAllOwnerByPage(pspSpecCheckCusVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pspSpecCheckCuss.size());
			pageSet(pspSpecCheckCuss, pspSpecCheckCusVo);
			list = (List<PspSpecCheckCusVO>) beansCopy(pspSpecCheckCuss, PspSpecCheckCusVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PspSpecCheckCusVO> queryAllCurrOrg(PspSpecCheckCusVO pspSpecCheckCusVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PspSpecCheckCus> pspSpecCheckCuss = pspSpecCheckCusDao.queryAllCurrOrgByPage(pspSpecCheckCusVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pspSpecCheckCuss.size());
		List<PspSpecCheckCusVO> list = null;
		try {
			pageSet(pspSpecCheckCuss, pspSpecCheckCusVo);
			list = (List<PspSpecCheckCusVO>) beansCopy(pspSpecCheckCuss, PspSpecCheckCusVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PspSpecCheckCusVO> queryAllCurrDownOrg(PspSpecCheckCusVO pspSpecCheckCusVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PspSpecCheckCus> pspSpecCheckCuss = pspSpecCheckCusDao.queryAllCurrDownOrgByPage(pspSpecCheckCusVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pspSpecCheckCuss.size());
		List<PspSpecCheckCusVO> list = null;
		try {
			pageSet(pspSpecCheckCuss, pspSpecCheckCusVo);
			list = (List<PspSpecCheckCusVO>) beansCopy(pspSpecCheckCuss, PspSpecCheckCusVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;

	}

	//批量查询数据处理
	@Override
	public int insertBatchInfo(List<PspSpecCheckCusVO> pspSpecCheckCusVOList) {
		logger.debug("本次批量处理的数据条数为：" + pspSpecCheckCusVOList.size());
		List<PspSpecCheckCus> PspSpecCheckCusList = new ArrayList<PspSpecCheckCus>();
		try {
			//复制list
			pspSpecCheckCusVOList.stream().forEach(i -> {
				PspSpecCheckCus bean = new PspSpecCheckCus();
				beanCopy(i,bean);
				PspSpecCheckCusList.add(bean);
			});
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			e.printStackTrace();
		}
		int num = pspSpecCheckCusDao.insertBatchInfo(PspSpecCheckCusList);
		return num;
	}

	@Override
	public List<PspSpecCheckCusVO> queryChkNameIsNull(PspSpecCheckCusVO pspSpecCheckCusVo) {
		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PspSpecCheckCusVO> list = null;
		try {
			List<PspSpecCheckCus> pspSpecCheckCuss = pspSpecCheckCusDao.queryChkNameIsNullAllByPage(pspSpecCheckCusVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pspSpecCheckCuss.size());
			pageSet(pspSpecCheckCuss, pspSpecCheckCusVo);
			list = (List<PspSpecCheckCusVO>) beansCopy(pspSpecCheckCuss, PspSpecCheckCusVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	/**
	 * 删除操作
	 */
	public int deleteChkNameIsNul(PspSpecCheckCusVO inPspSpecCheckCusVo) {
		logger.debug("当前删除数据条件为:"+ inPspSpecCheckCusVo);
		int num = 0;
		try {
			PspSpecCheckCus pspSpecCheckCus = new PspSpecCheckCus();
			beanCopy(inPspSpecCheckCusVo, pspSpecCheckCus);
			num = pspSpecCheckCusDao.deleteChkNameIsNul(pspSpecCheckCus);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPspSpecCheckCusVo +"删除的数据条数为"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteChkName(PspSpecCheckCusVO inPspSpecCheckCusVo) {
		logger.debug("当前删除数据条件为:"+ inPspSpecCheckCusVo);
		int num = 0;
		try {
			PspSpecCheckCus pspSpecCheckCus = new PspSpecCheckCus();
			beanCopy(inPspSpecCheckCusVo, pspSpecCheckCus);
			num = pspSpecCheckCusDao.deleteChkName(pspSpecCheckCus);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPspSpecCheckCusVo +"删除的数据条数为"+ num);
		return num;
	}

	/**
	 * 新增修改
	 */
	@Override
	public int insertOrUpdateByPk(PspSpecCheckCusVO pspSpecCheckCusVO){
		logger.debug("当前修改数据为："+pspSpecCheckCusVO.toString());
		int num =0;
		try{
			PspSpecCheckCus pspSpecCheckCus=new PspSpecCheckCus();
			beanCopy(pspSpecCheckCusVO,pspSpecCheckCus);
			setInsertDefaultProperty(pspSpecCheckCus);
			pspSpecCheckCus.setBizSerno(pspSpecCheckCusVO.getBizSerno());
			pspSpecCheckCus.setChkName(pspSpecCheckCusVO.getChkName());

			num=pspSpecCheckCusDao.insertOrUpdateByPk(pspSpecCheckCus);
		} catch (Exception e){
			logger.error("修改数据发生异常！",e);
			num=-1;
		}
		logger.debug("根据条件："+pspSpecCheckCusVO+"修改的数据条数为"+num);
		return num;
	}
	public PspSpecCheckCusVO queryByCusIdBizSerno(PspSpecCheckCusVO inPspSpecCheckCusVo) {

		logger.debug("当前查询参数信息为:"+ inPspSpecCheckCusVo);
		try {
			PspSpecCheckCus queryPspSpecCheckCus = new PspSpecCheckCus();
			beanCopy(inPspSpecCheckCusVo, queryPspSpecCheckCus);
			PspSpecCheckCus queryRslPspSpecCheckCus = pspSpecCheckCusDao.queryByCusIdBizSerno(queryPspSpecCheckCus);
			if (Objects.nonNull(queryRslPspSpecCheckCus)) {
				PspSpecCheckCusVO outPspSpecCheckCusVo = beanCopy(queryRslPspSpecCheckCus, new PspSpecCheckCusVO());
				logger.debug("当前查询结果为:"+ outPspSpecCheckCusVo.toString());
				return outPspSpecCheckCusVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	@Override
	public List<PspSpecCheckCusVO> queryByCusIdList(PspSpecCheckCusVO inPspSpecCheckCusVO) {
		logger.debug("当前查询本人所属数据信息的参数信息为:" + inPspSpecCheckCusVO);
		inPspSpecCheckCusVO.setChkName(RiskwarningConstant.PSP_CHK_NAME);
		List<PspSpecCheckCusVO> list = null;
		try {
			List<PspSpecCheckCus> pspSpecCheckCuss = pspSpecCheckCusDao.queryByCusIdList(inPspSpecCheckCusVO);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pspSpecCheckCuss.size());
			if (Objects.nonNull(pspSpecCheckCuss)) {
				list = (List<PspSpecCheckCusVO>) beansCopy(pspSpecCheckCuss, PspSpecCheckCusVO.class);
				return list;
			}
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return null;
	}

	@Override
	public List<PspSpecCheckCusVO> queryImportDatas(PspSpecCheckCusVO inPspSpecCheckCusVO) {
		logger.debug("当前查询本人所属数据信息的参数信息为:" + inPspSpecCheckCusVO);
		List<PspSpecCheckCusVO> list = null;
		try {
			List<PspSpecCheckCus> pspSpecCheckCuss = pspSpecCheckCusDao.queryImportDatas(inPspSpecCheckCusVO);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pspSpecCheckCuss.size());
			if (Objects.nonNull(pspSpecCheckCuss)) {
				list = (List<PspSpecCheckCusVO>) beansCopy(pspSpecCheckCuss, PspSpecCheckCusVO.class);
				return list;
			}
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return null;
	}

	@Override
	public int batchupdateBizSerno(List<PspSpecCheckCusVO> importDatas) {
		int result = 0;
		logger.debug("批量更新的数据长度为：" + importDatas.size());
		try {
			List<PspSpecCheckCus> importDatasList = (List<PspSpecCheckCus>) beansCopy(importDatas, PspSpecCheckCus.class);
			result = pspSpecCheckCusDao.batchupdateBizSerno(importDatasList);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			result = -1;
		}
		return result;
	}

	@Override
	public int updateByBizCus(PspSpecCheckCusVO inPspSpecCheckCusVO){
		int result = 0;
		logger.debug("更新数据为：" + inPspSpecCheckCusVO);
		try {
			PspSpecCheckCus pspSpecCheckCus = new PspSpecCheckCus();
			beanCopy(inPspSpecCheckCusVO,pspSpecCheckCus);
			result = pspSpecCheckCusDao.updateByBizCus(pspSpecCheckCus);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			result = -1;
		}
		return result;
	}

	@Override
	public List<PspSpecCheckCusVO> queryByBizSerno(String bizSerno){
		logger.debug("当前查询本人所属数据信息的流水号为:" + bizSerno);
		List<PspSpecCheckCusVO> list = null;
		try {
			List<PspSpecCheckCus> pspSpecCheckCuss = pspSpecCheckCusDao.queryByBizSerno(bizSerno);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pspSpecCheckCuss.size());
			if (Objects.nonNull(pspSpecCheckCuss)) {
				list = (List<PspSpecCheckCusVO>) beansCopy(pspSpecCheckCuss, PspSpecCheckCusVO.class);
				return list;
			}
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return null;
	}

}

